var app = getApp();
Page(Object.assign({},{
    data:{
        datalist : [],
        inited : false,
        goodslist : [{},{},{}],
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        
        var cid = options.id ? options.id : ( options.scene ? options.scene : 0 );
        var givecode = options.givecode ? options.givecode : 0;
        self.data.options = options;
        app.com.auth(function(user){
            app.com.http('card','POST',{op:'myinfo',id:cid,givecode:givecode},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        params : res.data.data.params,
                        userinfo : res.data.data.userinfo,
                        card : res.data.data.card,
                        shop : res.data.data.shop,
                        sharedata : res.data.data.sharedata,
                        allgoods : res.data.data.allgoods ? res.data.data.allgoods : [],
                        shoplist : res.data.data.shoplist ? res.data.data.shoplist : [],
                        qrcode : res.data.data.card.takedid > 0 ? app.com.murl('img',{op:'hexiaocard',cid:res.data.data.card.takedid,m:'zofui_sales'}) : '',
                    },function(){
                        self.setData({
                            inited : true,
                        });
                    });

                    wx.setNavigationBarTitle({
                      title:  res.data.data.card.name,
                    });

                    // 关闭下拉刷新
                    wx.stopPullDownRefresh();
                }else{
                    app.com.alert(res.data.message,function(){
                        app.com.backPage(options.zfid);
                    });
                }
            });
        });
    },
    toggleDetail(){
        this.setData({
            showDetail : !this.data.showDetail,
        })
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            isdown : true,
        });
        
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
    },
    onShareAppMessage : function(e){
        var self = this;
        if( e && e.target.dataset && e.target.dataset.type == 1 ){
            return {
                title: self.data.userinfo.nickname+'赠送你一枚优惠券',
                path: self.data.sharedata.givepath+'&givecode='+self.data.card.givecode,
                imageUrl : self.data.sharedata.img,
            }
        }else{
            return {
                title: self.data.sharedata.title,
                path: self.data.sharedata.path,
                imageUrl : self.data.sharedata.img,
            }
        }
    },
    takecard(e){
        var self = this;
        var postdata = {
            op : 'takecard',
            id : self.data.card.id,
        };
        app.com.http('card','POST',postdata,0,true,'','',function(res){
            app.com.toast( res.data.message );
            if (!res.data.errno && res.data) {
                self.setData({
                   ['card.istaked'] : 1,
                });
                return false;
            }
        });
    },
    chooseCard(e){
        this.setData({
            t : e.detail.value
        })
    },
    givefriend(){
        this.setData({
            isgive : true,
        })
    },
    closeoverlay(){
        this.setData({
            isgive : false,
        })
    },
    name(e){
        this.setData({
            name : e.detail.value
        })
    },
    tel(e){
        this.setData({
            tel : e.detail.value
        })
    },
    cardadclick(e){
        if(this.data.card.adtype == 0){
            this.navigateto(e);
        }else if(this.data.card.adtype == 2){
            app.com.toweburl(e);
        }
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    FormIdsubmit : function(e){
        if( app.globalData.formarr.length <= 20 ) app.globalData.formarr.push(e.detail.formId);
    },
    
}))